package com.example.emailcraft.controller;

import com.example.emailcraft.annotation.RequiredPermission;
import com.example.emailcraft.entity.common.Result;
import com.example.emailcraft.entity.request.SaveTemplateRequest;
import com.example.emailcraft.service.IUserTemplatesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author scj
 * @since 2025-01-21
 */
@RestController
@RequestMapping("/api/v1/userTemplates")
public class UserTemplatesController {
    @Autowired
    private IUserTemplatesService templateService;

    /***
     * 检查导出权限
     * @return ResponseEntity<Result<Object>>
     */
    @PostMapping("/check-export-permission")
    @RequiredPermission(value = "user")
    public ResponseEntity<Result<Object>> checkExportPermission() {
        return templateService.checkExportPermission();
    }

    /***
     * 保存模板
     * @param request 保存模板请求
     * @return ResponseEntity<Result<Object>>
     */
    @PostMapping("/save")
    @RequiredPermission(value = "user")
    public ResponseEntity<Result<Object>> saveTemplate(@RequestBody SaveTemplateRequest request) {
        return templateService.saveTemplate(request);
    }
}
